package com.example.springbootsfzy.controller.gengminghui;

import com.example.springbootsfzy.domain.CoursewareList;
import com.example.springbootsfzy.service.gengminghui.CoursewareListService;
import com.example.springbootsfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

@RestController
@RequestMapping("/coursewareList")
public class CoursewareListController {

    @Autowired
    private CoursewareListService coursewareListService;

//    查询所有课程列表信息
    @RequestMapping("/selectAll")
    public R selectAll(){
        return R.ok(coursewareListService.selectAll());
    }
//通过id删除课程列表信息
    @DeleteMapping("/deleteById")
    public R deleteByPrimaryKey(Integer id){
     int i = coursewareListService.deleteByPrimaryKey(id);
     if(i>0){
         return R.ok("删除成功");
     }else {
         return R.error("删除失败");}
    }

    //添加课程列表信息
    @PostMapping("/insert")
    public R insert(@RequestBody CoursewareList coursewareList){
        int i = coursewareListService.insert(coursewareList);
        if(i>0){
            return R.ok("添加成功");
        }else {
            return R.error("添加失败");}
    }
    //通过课程id查询列表信息
    @GetMapping("/selectByCourseId")
    public R selectByCourseId(Integer courseId){
        return R.ok(coursewareListService.selectByCourseId(courseId));

    }
    //修改课程列表信息
    @PutMapping("/updateById")
    public R updateByPrimaryKeySelective(@RequestBody CoursewareList coursewareList){
        int i = coursewareListService.updateByPrimaryKeySelective(coursewareList);
        if(i>0){
            return R.ok("修改成功");
        }else {
            return R.error("修改失败");
        }
    }
}
